package org.loginplugin;


import org.apache.ibatis.session.SqlSession;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.*;
import org.loginplugin.entity.LoginData;
import org.loginplugin.mapper.UserMapper;

import java.util.List;

/**
 * 事件处理器
 * Listener 一个触发所有事件监听器的接口
 */
public class EventProcessor implements Listener {

    /**
     * 处理玩家登录
     *
     * @param loginEvent 登录对象
     */
    @EventHandler
    public void onPlayerLogin(PlayerLoginEvent loginEvent) {
        System.out.println("loginEvent = " + loginEvent);
        LoginData.addPlayerName(loginEvent.getPlayer().getName());
    }

    /**
     * 处理玩家退出
     *
     * @param quitEvent 退出对象
     */
    @EventHandler
    public void onPlayerQuit(PlayerQuitEvent quitEvent) {
        LoginData.removePlayerName(quitEvent.getPlayer().getName());
    }

    @EventHandler
    public void restrictMove(PlayerMoveEvent e) {
        // 移动
        LoginData.cancelIfNotLoggedIn(e);
        // 你看这多方便
    }

    @EventHandler
    public void restrictInteract(PlayerInteractEvent e) {
        // 交互
        LoginData.cancelIfNotLoggedIn(e);
    }

    @EventHandler
    public void restrictInteractAtEntity(PlayerInteractAtEntityEvent e) {
        // 实体交互
        LoginData.cancelIfNotLoggedIn(e);
    }

    @EventHandler
    public void restrictPortal(PlayerPortalEvent e) {
        // 传送门
        LoginData.cancelIfNotLoggedIn(e);
    }

    @EventHandler
    public void restrictTeleport(PlayerTeleportEvent e) {
        // 传送
        LoginData.cancelIfNotLoggedIn(e);
    }

    @EventHandler
    public void restrictOpenInventory(InventoryOpenEvent e) {
        // 打开物品栏
        LoginData.cancelIfNotLoggedIn(e);
    }

}
